package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import com.lineage.server.world.WorldCrown;
import com.lineage.server.world.WorldDarkelf;
import com.lineage.server.world.WorldDragonKnight;
import com.lineage.server.world.WorldElf;
import com.lineage.server.world.WorldIllusionist;
import com.lineage.server.world.WorldKnight;
import com.lineage.server.world.WorldWizard;
import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1Who implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1Who.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1Who();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      Collection<L1PcInstance> players = World.get().getAllPlayers();
      String amount = String.valueOf(players.size());
      int a = WorldCrown.get().map().size();
      int b = WorldKnight.get().map().size();
      int c = WorldElf.get().map().size();
      int d = WorldWizard.get().map().size();
      int e = WorldDarkelf.get().map().size();
      int f = WorldDragonKnight.get().map().size();
      int g = WorldIllusionist.get().map().size();
      if (pc == null) {
        _log.warn("系统命令执行: who");
        _log.info("[王族]:" + a);
        _log.info("[骑士]:" + b);
        _log.info("[妖精]:" + c);
        _log.info("[法师]:" + d);
        _log.info("[黑妖]:" + e);
        _log.info("[龙骑]:" + f);
        _log.info("[幻术]:" + g);
      } else {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("目前线上有: " + amount));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("王族:" + a));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("骑士:" + b));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("妖精:" + c));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("法师:" + d));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("黑妖:" + e));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("龙骑:" + f));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("幻术:" + g));
      } 
    } catch (Exception e2) {
      if (pc == null) {
        _log.error("错误的命令格式: " + getClass().getSimpleName());
      } else {
        _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
      } 
    } 
  }
}
